<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );


/**
 * @package		Joomla
 * @subpackage	JobBoard
 */
class JobBoardTableJA_Transactions extends JTable
{
	/** @var int Primary key */
	var $id					= null;
	/** @var int */
	var $user_id			= null;
	
	var $created_date = '0000-00-00 00:00:00';
	var $processed_date = null;
	
	var $product_id			= null;
	/** @var time_stamp */					
	var $payment_method			= null;
	
	var $amount			= null;
	
	var $currency_code = null;
	var $reason = null;
	var $product_type			= null;
	var $reference			= null;
	var $completed			= 0;
	var $detail			= null;
	var $ip = null;
	var $txn_id = null;
	var $value = 0;
	var $value_type = null;
	var $begin_date = null;
	var $end_date = null;
	var $datas = null;
	
	/**
	* @param database A database connector object
	*/
	function __construct(&$db)
	{
		parent::__construct( '#__ja_transactions', 'id', $db );
	}
	
	/**
	 * Overloaded check function
	 *
	 * @access public
	 * @return boolean
	 * @see JTable::check
	 * @since 1.5
	 */
	function cleandata()
	{
		if ($this->id)
		{
			$db = JFactory::getDBO();
			$query = 'SELECT name FROM #__users WHERE id='.$this->user_id;
			$db->setQuery($query);
			$id = $db->loadObject();
			if (isset($id->name))
				JRequest::setVar('username',$id->name);
			switch (strtolower($this->product_type))
			{
				case 's':
					$query = "SELECT title FROM #__ja_subscriptions WHERE id=$this->product_id"; 
					break;
				case 'p':
					$query = "SELECT title FROM #__ja_posting_plans WHERE id=$this->product_id";
					break;
				case 'c':
					$query = "SELECT title FROM #__ja_credits WHERE id=$this->product_id";
					break;
			}
			$db->setQuery($query);
			$title = $db->loadObject();
			if (isset($title->title))
				JRequest::setVar('item_title',$title->title);
		}
	}	
	
	function check()
	{
		JFilterOutput::objectHTMLSafe($this,ENT_QUOTES,'');
		if(empty($this->user_id))
			return false;
				
		if(empty($this->pay_method))
			return false;				
		return true;
	}
}